<include file="../Public/admintop" />
<include file="../Public/adminleft" />
<script type="text/javascript">
function delall(){
	var id=$('input:checkbox[name^=id]:checked').map(function(){
		return $(this).val();
	}).get().join(",");
	if(!id){
		alert('请选择要删除的项!');
	}else{
		$.post("{:U('Brand/delete')}","id="+id);
		$('input[name^=id]:checked').parent().parent().remove();
	}
}

function status(id,_this){
	$.post("{:U('Brand/status')}",'id='+id,function(data){
		$('img',_this).attr('src',data.data['imgurl']);
	},'json');
	
}
$(document).ready (
function(){
	//选中
	$('#check').click(function(){
		$('input[name^=id]').attr('checked',$(this).attr('checked'));
	});
	$("a[name^='del_']").click(
	function(){
		var answer = confirm("确认要删除吗?");
		if(answer){
			window.location = $(this).attr("href");

		}
		else{

			$(this).attr("href","javascript:void(0);");

		}

	}
	);
	$('input:checkbox[name^=id]').each(function(i,el){
		var id=$(this).val();
		$(this).parent().next().children('a').click(function(){
			if(!$(this).next().length){
				$this=$(this);
				$(this).after("<p><textarea>"+$(this).text()+"</textarea><br/><input type='button' class='save' value='保存'/><input type='button' class='cannel' value='取消'/></p>");

				$(this).siblings().find('input.cannel').click(function(){
					$(this).parent('p').remove();
				});
				$(this).siblings().find('input.save').click(function(){
					$.post("{:U('Brand/rename')}",{ 'id':id,'name':$(this).siblings('textarea').val() },function(data,status){
						if(!data.status){
							alert(data.info);
						}else{
							$this.text(data['data'].name).siblings('p').remove();
						}
					},'json');
				});
			}
			return false;
		});
	}).parents('tr').mouseover(function(){
		$(this).css('background-color','#E6F7D4');
	}).mouseout(function(){
		$(this).css('background-color','#fff');
	});
}
);

</script>
<!-- Content (Right Column) -->
		<div id="content" class="box">

			<h1>品牌管理</h1>
            <p class="msg info">提示：</p>
            	
            <p id="btn-create" class="box">
              <a href="{:U('Brand/add')}">添加新品牌</a>
            </p>
            <table width="100%">
				<tr pid="0">
				    <th style="text-align:center" width="7%"><input type="checkbox" id="check" /></th>
				    <th style="text-align:center" width="15%">名称</th>
				    <th style="text-align:center" width="15%">排序</th>
                    <th style="text-align:center" width="7%">状态</th>
				    <th style="text-align:center" width="35%">描述</th>                 
                    <th style="text-align:center" >操作</th>
				</tr>
                <volist name="list" id="vo">
                <tr >
                    <td style="text-align:left" ><input type="checkbox" name="id[]" value="{$vo.id}" /></td>
				    <td style="text-align:left" id="classname" ><a href="javascript:void(0);">{$vo.name}</a></td>
				    <td style="text-align:left" >{$vo['sort']}</td>
                    <td style="text-align:left" ><a href="javascript:void(0);" onclick="javascript:status({$vo['id']},this);">{:getStatus($vo["status"],true)}</a></td>
                    <td style="text-align:left" >{$vo.title}</td>
                    <td style="text-align:center" ><a href="{:u('Brand/edit',array('id'=>$vo['id']))}">编辑</a>&nbsp;|&nbsp;<a name="del_{$vo.id}"  href="{:u('Brand/Delete',array('id'=>$vo['id']))}" >移除</a></td>
                </tr>
                </volist>
				
			</table>
			 <p class="t-left"><input type="button" value="批量删除" onclick="delall();" /></p>
            <p class="t-right">{$show}</p>
		</div> <!-- /content -->

<include file="../Public/adminfooter" />